<?php
include("include/config.inc.php");
if(!isset($_SESSION['s_activId']))
{
  $_SESSION['s_urlRedirectDir'] = $_SERVER['REQUEST_URI'];
  header("Location:checkLogin.php");
}
else
{
	if(isset($_POST['submit']))
	{
	  $partyName = isset($_REQUEST['partyName']) && $_REQUEST['partyName'] != '' ? $_REQUEST['partyName'] : "";
	  $address   = isset($_REQUEST['address']) && $_REQUEST['address'] != '' ? $_REQUEST['address'] : "";
	  $mobile    = isset($_REQUEST['mobile']) && $_REQUEST['mobile'] != '' ? $_REQUEST['mobile'] : 0;
	  $otherInfo = isset($_REQUEST['otherInfo']) && $_REQUEST['otherInfo'] != '' ? $_REQUEST['otherInfo'] : "";
	  
	  $insertParty = "INSERT INTO party (partyName,address,mobile,otherInfo)
	                        VALUES ('".$partyName."','".addslashes($address)."',".$mobile.",'".$otherInfo."')";
	  $insertPartyRes = mysql_query($insertParty);
	  if(!$insertPartyRes)
	  {
	  	echo "Insert Fail";
	  }
	  else
	  {
	    header("Location:party.php");
	  }
	}
	$partyArray = array();
	$i = 0;
	$selectItem = "SELECT partyId,partyName,address,mobile,otherInfo
	                 FROM party
	                ORDER BY partyName";
	$selectItemRes = mysql_query($selectItem);
	while($partyRow = mysql_fetch_array($selectItemRes))
	{
		$partyArray[$i]['partyId']   = $partyRow['partyId'];
		$partyArray[$i]['partyName'] = $partyRow['partyName'];
		$partyArray[$i]['address']   = $partyRow['address'];
		$partyArray[$i]['mobile']    = $partyRow['mobile'];
		$partyArray[$i]['otherInfo'] = $partyRow['otherInfo'];
		$i++;
	}
}

include("./bottom.php");
$smarty->assign("partyArray",$partyArray);
$smarty->display("party.tpl");
?>